<template>
  <Table
    ref="tableRef"
    :url="URL_PAGINGCECCONFIG"
    :columns="data.columns"
    :handles="data.handles"
    :query="data.query"
    :toolbar="data.toolbar"
  ></Table>
</template>

<script lang="ts" setup name="interconnectionKeyList">
import Table from '@/components/table/index.vue';
import { queryDicByParent } from '@/service/apis/api';
import { URL_PAGINGCECCONFIG } from '@/service/apis/docking';

const router = useRouter();

const tableRef = ref();

const emit = defineEmits(['get-update']);
onActivated(() => {
  emit('get-update', (flag: boolean) => {
    if (flag) {
      tableRef.value?.getData();
    }
  });
});

const data = reactive({
  columns: [
    {
      prop: 'channelName',
      label: '平台运营商',
    },
    {
      prop: 'orgName',
      label: '企业名称',
    },
    {
      prop: 'type',
      label: '企业类型',
      dic: [] as any,
    },
  ],
  toolbar: [
    {
      label: '新增',
      permission: 'interconnectionKeyList.add',
      icon: 'icon-add',
      type: 'primary',
      handle: (row: any) => {
        router.push({
          name: 'interconnectionKeyAdd',
        });
      },
    },
  ],
  query: [
    {
      label: '企业名称',
      prop: 'orgName',
      comName: 'input',
      props: {
        placeholder: '请输入企业名称',
      },
    },
    {
      label: '企业类型',
      prop: 'type',
      comName: 'select',
      props: {
        placeholder: '请选择企业类型',
        options: [] as any,
      },
    },
    {
      label: '平台运营商',
      prop: 'channelName',
      comName: 'input',
      props: {
        placeholder: '请输入平台运营商',
      },
    },
  ],
  handles: [
    {
      label: '详情',
      permission: 'interconnectionKeyList.see',
      handle: (row: any) => {
        router.push({
          name: 'interconnectionKeyDetail',
          query: { id: row.id },
        });
      },
    },
    {
      label: '修改',
      permission: 'interconnectionKeyList.edit',
      handle: (row: any) => {
        router.push({
          name: 'interconnectionKeyEdit',
          query: { id: row.id },
        });
      },
    },
  ],
});

queryDicByParent({
  listDtos: ['cecOrgType'],
}).then((res: any) => {
  if (res) {
    data.query[1].props.options = [...res.cecOrgType];
    data.columns[2].dic = [...res.cecOrgType];
  }
});
</script>